package com.kuang.demo.service.wx;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kuang.demo.mapper.wx.WxBrandMapper;
import com.kuang.demo.pojo.wx.Cskaoyanmall_brand;
import com.kuang.demo.vo.wx.WxQueryBrandDetailVO;
import com.kuang.demo.vo.wx.WxQueryBrandListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 郭浩 on 2020/11/5 15:28
 */
@Service
public class WxBrandServiceImpl implements WxBrandService{
    @Autowired
    WxBrandMapper wxBrandMapper;
    @Override
    public WxQueryBrandListVO querybandList(int page, int size) {
//        wxBrandMapper.sele
        WxQueryBrandListVO wxQueryBrandListVO = new WxQueryBrandListVO();
        //查询到所有得结果
        Page<Cskaoyanmall_brand> cskaoyanmall_brandPage = wxBrandMapper.selectPage(new Page<>(page, size), null);
        List<Cskaoyanmall_brand> records = cskaoyanmall_brandPage.getRecords();
        //将列传到list
        List<WxQueryBrandListVO.BrandListBean> list2 = new ArrayList<>();
        for (int i = 0; i < records.size(); i++) {
            WxQueryBrandListVO.BrandListBean brandListBean = new WxQueryBrandListVO.BrandListBean();
            brandListBean.setDesc(records.get(i).getDesc());
            brandListBean.setFloorPrice(records.get(i).getFloorPrice());
            brandListBean.setId(records.get(i).getId());
            brandListBean.setName(records.get(i).getName());
            brandListBean.setPicUrl(records.get(i).getPicUrl());
            list2.add(brandListBean);
        }

        wxQueryBrandListVO.setBrandList(list2);
        Long pages = cskaoyanmall_brandPage.getPages();
        wxQueryBrandListVO.setTotalPages(pages.intValue());
        return wxQueryBrandListVO;
    }

    @Override
    public WxQueryBrandDetailVO queryBrandDetail(Integer id) {
        Cskaoyanmall_brand cskaoyanmall_brand = wxBrandMapper.selectOne(new QueryWrapper<Cskaoyanmall_brand>().eq("id", id));
        WxQueryBrandDetailVO wxQueryBrandDetailVO = new WxQueryBrandDetailVO();
        wxQueryBrandDetailVO.setBrand(cskaoyanmall_brand);
        return wxQueryBrandDetailVO;
    }
}
